<template>
  <transition name="confirm-fade">
    <div class="confirm" v-show="showFlag">
      <div class="confirm-wrapper">
        <div class="confirm-content">
          <p class="text">{{title}}</p>
          <div class="confirm-operate">
            <!--              取消-->
            <div @click="cancle" class="confirm-btn">{{btnCancle}}</div>
            <!--              确认-->
            <div @click="sure" class="confirm-btn left">{{btnSure}}</div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      // 弹窗标题
      title: {
        type: String,
        default: '是否全部清除？'
      },
      // 两个确认键
      btnCancle: {
        type: String,
        default: '取消'
      },
      btnSure: {
        type: String,
        default: '确定'
      }
    },
    data () {
      return {
        // 控制弹出框的show
        showFlag: false
      }
    },
    methods: {
      // 展示弹出框
      show () {
        this.showFlag = true
      },
      // 隐藏弹出框
      hide () {
        this.showFlag = false
      },
      // 取消
      cancle () {
        this.hide()
      },
      // 确认
      sure () {
        this.hide()
        // 派发出去，让外部组件改变showFlag
        this.$emit('sureClear')
      }
    }
  }
</script>

<style scoped lang="stylus">
  @import "~common/stylus/variable.styl"
  .confirm
    position: fixed
    left: 0
    top: 0
    bottom: 0
    right: 0
    z-index: 998
    background: $color-background-d

    .confirm-wrapper
      position: absolute
      top: 50%
      left: 50%
      z-index: 999
      transform: translate3d(-50%, -50%, 0)

      .confirm-content
        width: 270px
        border-radius: 13px
        background: $color-highlight-background

        .text
          padding: 19px 15px
          text-align: center
          line-height: 22px
          font-size: $font-size-large
          color: $color-text-d

        .confirm-operate
          display: flex
          align-items: center
          text-align: center
          font-size: $font-size-large

          .confirm-btn
            flex: 1
            color: $color-text-d
            line-height: 21px
            padding: 10px 0
            border-top: 1px solid $color-background-d

            &.left
              border-left: 1px solid $color-background-d
</style>
